/*
 * AnswerEdit.cpp
 *
 *  Created on: 29.3.2010
 *      Author: mamannis
 */

#include "answeredit.h"
#include <QDebug>
#include <QKeyEvent>

AnswerEdit::AnswerEdit( QWidget* parent )
: QLineEdit( parent )
{
}

AnswerEdit::~AnswerEdit()
{
}

void AnswerEdit::keyPressEvent(QKeyEvent *e)
{
    const int key = e->key();
	
    if ( key >= Qt::Key_0 && key <= Qt::Key_9 )
    {
        m_answerText.append(e->text());
        e->accept();
        setText(m_answerText);
        return;
    }

    if ( key == Qt::Key_Period || key == Qt::Key_Backspace )
    {
        if ( m_answerText.isEmpty() )
        {
            e->accept();
            qDebug() << " Key_Backspace empty: " << e;
            m_answerText.append( "-" );
            setText(m_answerText);
        }
        else
        {
            m_answerText.remove( m_answerText.length()-1, 1 );
            setText(m_answerText);
        }
        return;
    }
    else if ( key == Qt::Key_Select )
    {
        emit returnPressed();
        e->accept();
        m_answerText.clear();
        return;
    }
    //QLineEdit::keyPressEvent( e );
}


void AnswerEdit::focusInEvent( QFocusEvent * e )
{
    m_answerText.clear();
    QLineEdit::focusInEvent( e );
}

// end of file
